package com.cneport.das.server.util.receive;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.support.destination.DynamicDestinationResolver;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;


/**
 * @author GavinZhang
 * @version 1.0
 * @desc： Jms配置文件
 * @company 东方物通科技有限（北京）公司
 * @date 2021/9/9 16:12
 */
@Configuration
@ConditionalOnProperty(name = "mq.listener.enable", havingValue = "true")
public class JmsReceiverConf {
    @Value("${jms.listener.threadPool.corePoolSize}")
    private int corePoolSize;
    @Value("${jms.listener.threadPool.maxPoolSize}")
    private int maxPoolSize;
    @Value("${jms.listener.threadPool.keepAliveSeconds}")
    private int keepAliveSeconds;
    @Value("${jms.listener.threadPool.queueCapacity}")
    private int queueCapacity;


    @Bean
    DynamicDestinationResolver jmsDestinationResolver() {
        return new DynamicDestinationResolver();
    }

    @Bean
    ThreadPoolTaskExecutor jmsListenerTaskExecutor() {
        ThreadPoolTaskExecutor threadPool = new ThreadPoolTaskExecutor();
        threadPool.setMaxPoolSize(maxPoolSize);
        threadPool.setCorePoolSize(corePoolSize);
        threadPool.setQueueCapacity(queueCapacity);
        threadPool.setKeepAliveSeconds(keepAliveSeconds);
        threadPool.setThreadNamePrefix("jmsListenerTaskExecutor");
        return threadPool;
    }


}
